package com.xiaoy.core.basic.organization.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SQLQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xiaoy.core.basic.organization.entity.PartyType;
import com.xiaoy.dao.DaoUtil;


@Service
public class PartyTypeSerivce {
	
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource(name="daoUtil")
	private DaoUtil<PartyType,Long> daoUtil;
	
//	@Autowired
//	private OrganizationDao daoUtil;
	
	
	private String tablename="bas_org_Partytype t ";
	@Transactional
	public void save(PartyType type) {
//		try {
			daoUtil.save(type);
			/*}catch (Exception e) {
			throw new SystemException("保存");
		}*/
		
	}
	
	public PartyType getById (long id) {
		
		return (PartyType)daoUtil.getSession().get(PartyType.class, id);
//		return daoUtil.get(new Long(id));
	}
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<PartyType> getAll () {
//		
		String sql ="select * from "+tablename +"order by priority asc";
		
		SQLQuery query = daoUtil.getSession().createSQLQuery(sql);
//		
		query.addEntity(PartyType.class);
//		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		logger.info("获得所有的组织机构类型 sql:"+sql);
		return query.list();
//		return daoUtil.getAll();
	}
	
	@Transactional
	public PartyType delete (long id){
		
		PartyType type = getById(id);
		return delete(type);
	}
	public PartyType delete (PartyType partyType){
		daoUtil.delete(partyType);
		return partyType;
	}
	 
	
}
